package edu.suda.xsap.controller;

import edu.suda.xsap.common.Result;
import edu.suda.xsap.entity.ChartData;
import edu.suda.xsap.dto.CourseDto;
import edu.suda.xsap.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/course")
@Slf4j
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/listc")
    public Result list() {
        try {
            List<CourseDto> courseDtos = courseService.findAll();
            return Result.success(courseDtos);
        } catch (Exception e) {
            log.error("查询失败", e);
            return Result.failure(e.getMessage(), e);
        }
    }
    @GetMapping("/count")
    public Result getCourseCount() {
        try {
            List<ChartData> courseCount = courseService.getCount();
            return Result.success(courseCount);
        } catch (Exception e) {
            log.error("查询失败", e);
            return Result.failure(e.getMessage(), e);
        }
    }
}